//
//  HMGradingAssignmentVC.m
//  优学荟管理系统
//
//  Created by 陈辉明 on 2017/12/26.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HMGradingAssignmentVC.h"
#import "HMGradingAssignmentModel.h"
#import "HNAudioTapGestureRecognizer.h"
#import "EMCDDeviceManager.h"
#import "HNAudioView.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import "CourseEvaluateAudioView.h"
#import "EMCDDeviceManager.h"
#import "MBSmartVideoView.h"
#import "MyHappyTimeVC.h"
#import  <UIButton+WebCache.h>
#import "UIButton+ZYWebCaches.h"
@interface HMGradingAssignmentVC () <UITextViewDelegate,UITextFieldDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;//题目
@property (weak, nonatomic) IBOutlet UILabel *workContenLabel;//作业内容
@property (weak, nonatomic) IBOutlet UIImageView *workOnePic;
@property (weak, nonatomic) IBOutlet UIImageView *workTwoPic;
@property (weak, nonatomic) IBOutlet UIImageView *workThreePic;

@property (weak, nonatomic) IBOutlet UILabel *uploadContenLabel;//提交内容
@property (weak, nonatomic) IBOutlet UIImageView *uploadOnePic;
@property (weak, nonatomic) IBOutlet UIImageView *uploadTwoPic;
@property (weak, nonatomic) IBOutlet UIImageView *uploadThreePic;

@property (weak, nonatomic) IBOutlet UITextView *workRemarkTextView;//作业评语
@property (weak, nonatomic) IBOutlet UIButton *workRemarkButton;//作业评语相机按钮
@property (weak, nonatomic) IBOutlet UITextField *workGradeTextField;//作业评分
@property (nonatomic,strong) NSMutableArray *dataSource;
@property(nonatomic,strong) HMGradingAssignmentModel *model;
@property (nonatomic, strong) HNAudioView *AudioView;

@property (weak, nonatomic) IBOutlet UIButton *workOnePlayBtn;
@property (weak, nonatomic) IBOutlet UIButton *workTwoPlayBtn;
@property (weak, nonatomic) IBOutlet UIButton *workThreePlayBtn;
@property (weak, nonatomic) IBOutlet UIButton *upLoadOnePlayBtn;
@property (weak, nonatomic) IBOutlet UIButton *upLoadTwoPlayBtn;
@property (weak, nonatomic) IBOutlet UIButton *upLoadThreePlayBtn;
// 相册摄像机
@property (nonatomic, strong) UIImagePickerController *ImagePicker;
@property (nonatomic, assign) BOOL SaveVideo;
@property(nonatomic,copy) NSString *files;//图片,音频上传成功后记录的ID
@property(nonatomic,assign) BOOL isDelect;//点击相机按钮是上传还是删除
@property(nonatomic,copy) NSString *vedioStr;//返回视频地址
@property(nonatomic,copy) NSString *vedioImage;//返回视频图片

@property(nonatomic,assign) BOOL isVedio;//是否是视频

@property (weak, nonatomic) IBOutlet UIView *faildView;//数据加载失败遮盖View
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activity;//菊花
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *workOnePicHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *workOnePicWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *upLoadPicHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *upLoadPicWidth;

@end

@implementation HMGradingAssignmentVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNetWork];
    self.workRemarkTextView.delegate = self;
    self.workGradeTextField.delegate = self;
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTargat:self action:@selector(leftBarButtonItemAction) image:@"icon_back_student_sign" highImage:@"icon_back_student_sign"];
}

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ColorRGB(255,255,255)}]; //设置标题颜色
    [self.navigationController.navigationBar setBackgroundImage:[LLTools createImageWithColor:ColorRGB(47, 204, 138)] forBarMetrics:(UIBarMetricsDefault)];//设置导航栏颜色

    [SVProgressHUD dismiss];
}


- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar setBackgroundImage:[LLTools createImageWithColor:ColorRGB(255, 255, 255)] forBarMetrics:(UIBarMetricsDefault)];//设置导航栏颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ColorRGB(51,51,51)}];//设置标题颜色
}


- (void)leftBarButtonItemAction{
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - 网络请求

- (void)setNetWork{
    
    // http://192.168.0.113:8080/StarShine/ys/assignHomework.do?action=getTopicAndAnswer&answerId=11
    
//    NSString *url= [NSString stringWithFormat:@"assignHomework.do?action=getTopicAndAnswer&answerId=%@",@"11"];
     NSString *url= [NSString stringWithFormat:@"assignHomework.do?action=getTopicAndAnswer&answerId=%@",self.answerId];
    
    NSLog(@"%@ %@",LLBaseURL(url),[AccountTool shareAccountTool].currentAccount.authCode);
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    
    [NetManager Get:LLBaseURL(url) Auth:YES Params:nil Success:^(id Obj) {
        [self.activity stopAnimating];
        if ([[Obj valueForKey:@"code"]integerValue] == 1000) {
            self.faildView.hidden = YES;
            self.model = nil;
            [SVProgressHUD dismiss];
            HMGradingAssignmentModel *model = [HMGradingAssignmentModel HMGradingAssignmentModelWithDict:Obj[@"t"]];
            self.model = model;
        }
        
        else {
            [SVProgressHUD showErrorWithStatus:Obj[@"msg"]];
            self.faildView.hidden = NO;
           
        }
        
       
        
        
    } Fail:^(NSError *Error) {
        [SVProgressHUD showErrorWithStatus:NetErr];
        [self.activity stopAnimating];
        self.faildView.hidden = NO;
    }];
    
    
    
    
}



-(void)setModel:(HMGradingAssignmentModel *)model {
    _model = model;

    self.titleLabel.text = [NSString stringWithFormat:@"%@",model.Onemodel.title];
    self.workContenLabel.text = [NSString stringWithFormat:@"%@",model.Onemodel.content];
    self.uploadContenLabel.text = model.twoModel.answerContent != nil && ![model.twoModel.answerContent isKindOfClass:[NSNull class]] && model.twoModel.answerContent.length > 0 ? model.twoModel.answerContent:@"  ";
    
    __block typeof(self) weakSelf = self;
    
    self.workOnePic.userInteractionEnabled = YES;
    self.workTwoPic.userInteractionEnabled = YES;
    self.workThreePic.userInteractionEnabled = YES;
    self.uploadOnePic.userInteractionEnabled = YES;
    self.uploadTwoPic.userInteractionEnabled = YES;
    self.uploadThreePic.userInteractionEnabled = YES;
    if (model.Onemodel.oneDataArray.count == 0) {
        self.workOnePicWidth.constant = 0;
        self.workOnePicHeight.constant = 0;
    }else {
        self.workOnePicWidth.constant = 51;
        self.workOnePicHeight.constant = 51;
    }
    if (model.twoModel.twoDataArray.count == 0) {
        self.upLoadPicWidth.constant = 0;
        self.upLoadPicHeight.constant = 0;
    }else {
        self.upLoadPicWidth.constant = 82;
        self.upLoadPicHeight.constant = 82;
    }
    
    
    //作业内容
    if (model.Onemodel.oneDataArray.count == 1 ) {//1个数据时
        self.workOnePic.hidden = NO;
        self.workTwoPic.hidden = YES;
        self.workThreePic.hidden = YES;
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"1"]) {//返回是图片
             HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.workOnePic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.oneDataArray[0]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.workOnePic.image;
            }];
            [self.workOnePic addGestureRecognizer:Tap];
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"2"]) {//返回是音频
            self.workOnePic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.Onemodel.oneDataArray[0];
            [self.workOnePic addGestureRecognizer:Tap];
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"3"]) {//返回是视频
            self.workOnePlayBtn.hidden = NO;
            self.workTwoPlayBtn.hidden = YES;
            self.workThreePlayBtn.hidden = YES;
            [self.workOnePic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.videoImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.Onemodel.video;
                [weakSelf.workOnePic addGestureRecognizer:Tap];
            }];
            
        }
        
    }else if (model.Onemodel.oneDataArray.count == 2) {//2个数据时
        self.workOnePic.hidden = NO;
        self.workTwoPic.hidden = NO;
        self.workThreePic.hidden = YES;
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"1"]) {//第一张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.workOnePic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.oneDataArray[0]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.workOnePic.image;
            }];
            [self.workOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"2"]) {//第一张返回是音频
            self.workOnePic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.Onemodel.oneDataArray[0];
            [self.workOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"3"]) {//第一张返回是视频
            [self.workOnePic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.videoImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.Onemodel.video;
                [weakSelf.workOnePic addGestureRecognizer:Tap];
            }];
            self.workOnePlayBtn.hidden = NO;
            self.workTwoPlayBtn.hidden = YES;
            self.workThreePlayBtn.hidden = YES;
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[1]] isEqualToString:@"1"]) {//第二张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.workTwoPic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.oneDataArray[1]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.workTwoPic.image;
            }];
            [self.workTwoPic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[1]] isEqualToString:@"2"]) {//第二张返回是音频
            self.workTwoPic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.Onemodel.oneDataArray[1];
            [self.workTwoPic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[1]] isEqualToString:@"3"]) {//第二张返回是视频
            self.workOnePlayBtn.hidden = YES;
            self.workTwoPlayBtn.hidden = NO;
            self.workThreePlayBtn.hidden = YES;
            [self.workTwoPic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.videoImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.Onemodel.video;
                [weakSelf.workTwoPic addGestureRecognizer:Tap];
            }];
            
        }
        
    }else if (model.Onemodel.oneDataArray.count == 3) {//3个数据时
        self.workOnePic.hidden = NO;
        self.workTwoPic.hidden = NO;
        self.workThreePic.hidden = NO;
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"1"]) {//第一张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.workOnePic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.oneDataArray[0]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.workOnePic.image;
            }];
            [self.workOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"2"]) {//第一张返回是音频
            self.workOnePic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.Onemodel.oneDataArray[0];
            [self.workOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[0]] isEqualToString:@"3"]) {//第一张返回是视频
            self.workOnePlayBtn.hidden = NO;
            self.workTwoPlayBtn.hidden = YES;
            self.workThreePlayBtn.hidden = YES;
            [self.workOnePic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.videoImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.Onemodel.video;
                [weakSelf.workOnePic addGestureRecognizer:Tap];
            }];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[1]] isEqualToString:@"1"]) {//第二张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.workTwoPic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.oneDataArray[1]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.workTwoPic.image;
            }];
            [self.workTwoPic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[1]] isEqualToString:@"2"]) {//第二张返回是音频
            self.workTwoPic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.Onemodel.oneDataArray[1];
            [self.workTwoPic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[1]] isEqualToString:@"3"]) {//第二张返回是视频
            self.workOnePlayBtn.hidden = YES;
            self.workTwoPlayBtn.hidden = NO;
            self.workThreePlayBtn.hidden = YES;
            [self.workTwoPic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.videoImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.Onemodel.video;
                [weakSelf.workTwoPic addGestureRecognizer:Tap];
            }];
            
        }
        
        
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[2]] isEqualToString:@"1"]) {//第三张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.workThreePic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.oneDataArray[2]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.workThreePic.image;
            }];
            [self.workThreePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[2]] isEqualToString:@"2"]) {//第三张返回是音频
            self.workThreePic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.Onemodel.oneDataArray[2];
            [self.workThreePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.Onemodel.oneDataArray[2]] isEqualToString:@"3"]) {//第三张返回是视频
            self.workOnePlayBtn.hidden = YES;
            self.workTwoPlayBtn.hidden = YES;
            self.workThreePlayBtn.hidden = NO;
            [self.workThreePic sd_setImageWithURL:[NSURL URLWithString:model.Onemodel.videoImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.Onemodel.video;
                [weakSelf.workThreePic addGestureRecognizer:Tap];
            }];
            
        }
    }
    
    
    
    //提交内容
    if (model.twoModel.twoDataArray.count == 1) {//1个数据时
        self.uploadOnePic.hidden = NO;
        self.uploadTwoPic.hidden = YES;
        self.uploadThreePic.hidden = YES;
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"1"]) {//返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.uploadOnePic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.twoDataArray[0]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.uploadOnePic.image;
            }];
            [self.uploadOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"2"]) {//返回是音频
            self.uploadOnePic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.twoModel.twoDataArray[0];
            [self.uploadOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"3"]) {//返回是视频
            self.upLoadOnePlayBtn.hidden = NO;
            self.upLoadTwoPlayBtn.hidden = YES;
            self.upLoadThreePlayBtn.hidden = YES;
            [self.uploadOnePic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.answerImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.twoModel.answerVideo;
                [weakSelf.uploadOnePic addGestureRecognizer:Tap];
            }];
            
        }
        
        
    }else if (model.twoModel.twoDataArray.count == 2) {//两个数据
        self.uploadOnePic.hidden = NO;
        self.uploadTwoPic.hidden = NO;
        self.uploadThreePic.hidden = YES;
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"1"]) {//第一张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.uploadOnePic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.twoDataArray[0]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.uploadOnePic.image;
            }];
            [self.uploadOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"2"]) {//第一张返回是音频
            self.uploadOnePic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.twoModel.twoDataArray[0];
            [self.uploadOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"3"]) {//第一张返回是视频
            self.upLoadOnePlayBtn.hidden = NO;
            self.upLoadTwoPlayBtn.hidden = YES;
            self.upLoadThreePlayBtn.hidden = YES;
            [self.uploadOnePic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.answerImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.twoModel.answerVideo;
                [weakSelf.uploadOnePic addGestureRecognizer:Tap];
            }];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[1]] isEqualToString:@"1"]) {//第二张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.uploadTwoPic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.twoDataArray[1]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.uploadTwoPic.image;
            }];
            [self.uploadTwoPic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[1]] isEqualToString:@"2"]) {//第二张返回是音频
            self.uploadTwoPic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.twoModel.twoDataArray[1];
            [self.uploadTwoPic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[1]] isEqualToString:@"3"]) {//第二张返回是视频
            self.upLoadOnePlayBtn.hidden = YES;
            self.upLoadTwoPlayBtn.hidden = NO;
            self.upLoadThreePlayBtn.hidden = YES;
            [self.uploadTwoPic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.answerImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.twoModel.answerVideo;
                [weakSelf.uploadTwoPic addGestureRecognizer:Tap];
            }];
        }
        
    }else if (model.twoModel.twoDataArray.count == 3) {
        self.uploadOnePic.hidden = NO;
        self.uploadTwoPic.hidden = NO;
        self.uploadThreePic.hidden = NO;
        
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"1"]) {//第一张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.uploadOnePic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.twoDataArray[0]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.uploadOnePic.image;
            }];
            [self.uploadOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"2"]) {//第一张返回是音频
            self.uploadOnePic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.twoModel.twoDataArray[0];
            [self.uploadOnePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[0]] isEqualToString:@"3"]) {//第一张返回是视频
            self.upLoadOnePlayBtn.hidden = NO;
            self.upLoadTwoPlayBtn.hidden = YES;
            self.upLoadThreePlayBtn.hidden = YES;
            [self.uploadOnePic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.answerImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.twoModel.answerVideo;
                [weakSelf.uploadOnePic addGestureRecognizer:Tap];
            }];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[1]] isEqualToString:@"1"]) {//第二张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.uploadTwoPic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.twoDataArray[1]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.uploadTwoPic.image;
            }];
            [self.uploadTwoPic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[1]] isEqualToString:@"2"]) {//第二张返回是音频
            self.uploadTwoPic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.twoModel.twoDataArray[1];
            [self.uploadTwoPic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[1]] isEqualToString:@"3"]) {//第二张返回是视频
            self.upLoadOnePlayBtn.hidden = YES;
            self.upLoadTwoPlayBtn.hidden = NO;
            self.upLoadThreePlayBtn.hidden = YES;
            [self.uploadTwoPic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.answerImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.twoModel.answerVideo;
                [weakSelf.uploadTwoPic addGestureRecognizer:Tap];
            }];
        }
        
        
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[2]] isEqualToString:@"1"]) {//第三张返回是图片
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(ImgAddTap:)];
            [self.uploadThreePic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.twoDataArray[2]] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                Tap.Img = self.uploadThreePic.image;
            }];
            [self.uploadThreePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[2]] isEqualToString:@"2"]) {//第三张返回是音频
            self.uploadThreePic.image = [UIImage imageNamed:@"iocn_voice"];
            HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayerAddTap:)];
            Tap.UrlStr = model.twoModel.twoDataArray[2];
            [self.uploadThreePic addGestureRecognizer:Tap];
            
        }
        if ([[self JudgeStrIsImagOrAudio:model.twoModel.twoDataArray[2]] isEqualToString:@"3"]) {//第三张返回是视频
            self.upLoadOnePlayBtn.hidden = YES;
            self.upLoadTwoPlayBtn.hidden = YES;
            self.upLoadThreePlayBtn.hidden = NO;
            [self.uploadThreePic sd_setImageWithURL:[NSURL URLWithString:model.twoModel.answerImg] placeholderImage:[UIImage imageNamed:@"icon_add_default1"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                HNAudioTapGestureRecognizer *Tap = [[HNAudioTapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayVedioButton:)];
                Tap.UrlStr = model.twoModel.answerVideo;
                [weakSelf.uploadThreePic addGestureRecognizer:Tap];
            }];
            
        }
    }
    
    
    
}




//判断是图片1音频2还是视频3
- (NSString *)JudgeStrIsImagOrAudio:(NSString *)UrlStr
{
    
    NSString *Str = [UrlStr pathExtension];
    if ([Str isEqualToString:@"mp3"] ||
        [Str isEqualToString:@"ogg"] ||
        [Str isEqualToString:@"amr"])
    {
        return @"2";
    }
    else if ([Str isEqualToString:@"mp4"]){
        return @"3";
    }
    
    else
    {
        return @"1";
    }
    
}



#pragma mark - 图片全屏
/** 图片全屏手势 */
- (void)ImgAddTap:(HNAudioTapGestureRecognizer *)Tap
{
    [self ImgControllerWithImg:Tap.Img];
}
/** 图片全屏操作 */
- (void)ImgControllerWithImg:(UIImage *)Img
{
    [self.AudioView OpenWithImg:Img];
}


#pragma mark - 音频播放
/** 播放手势 */
- (void)PlayerAddTap:(HNAudioTapGestureRecognizer *)Tap
{
    [self PlayerWithUrlStr:Tap.UrlStr];
}
/** 音频播放 */
- (void)PlayerWithUrlStr:(NSString *)UrlStr
{
    [self RefreshDataForAmr:UrlStr Complete:^(NSString *FullPath) {
        
        FullPath = [FullPath substringFromIndex:7];
        [[EMCDDeviceManager sharedInstance] asyncPlayingWithPath:FullPath completion:^(NSError *error) {
            NSLog(@"播放完成");
        }];
    }];
}

/**
 获取amr文件
 */
- (void)RefreshDataForAmr:(NSString *)UrlStr Complete:(void(^)(NSString *FullPath))Complete
{
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"AMR"];
    
    [NetManager DownLoadFileWithUrlStr:UrlStr FileName:[UrlStr lastPathComponent] Path:path Progress:^(CGFloat Index) {
        
        
    } Complete:^(NSString *FullPath, NSError *Err) {
        
        [MBProgressHUD hideHUD];
        if (Err)
        {
            [MBProgressHUD showError:@"音频文件播放失败"];
        }
        else
        {
            Complete (FullPath);
        }
    }];
}

- (HNAudioView *)AudioView
{
    if (!_AudioView)
    {
        _AudioView = [[HNAudioView alloc] init];
    }
    return _AudioView;
}

//视频播放

- (void)clickPlayVedioButton:(HNAudioTapGestureRecognizer *)Tap {
    NSURL *URL = [NSURL URLWithString:Tap.UrlStr];
    MPMoviePlayerViewController  * moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:URL];
    [self  presentMoviePlayerViewControllerAnimated:moviePlayerController];
    moviePlayerController.moviePlayer.movieSourceType=MPMovieSourceTypeFile;
    
}

#pragma mark - 点击了确认按钮

- (IBAction)clickSureButton:(id)sender {
    
    //http://192.168.0.113:8080/StarShine/ys/assignHomework.do?action=savePostil&answerId=11&files=1008,1009&content=帅气大焕哥&score=12&video&videoImg
    
    
    if (self.workGradeTextField.text &&self.workGradeTextField.text.length > 0) {
        if (0 <=[self.workGradeTextField.text intValue] && [self.workGradeTextField.text intValue]<=100) {
            [SVProgressHUD show];
//NSString *escapedPath =
           
            NSDictionary *Params = @{
                                     @"action"    :@"savePostil",
                                     @"answerId"  :self.answerId,
                                     @"content" : self.workRemarkTextView.text?self.workRemarkTextView.text:@"",
                                     @"files"   :self.files?self.files:@"",
                                     @"video"   :self.vedioStr?self.vedioStr:@"",
                                     @"videoImg":self.vedioImage?self.vedioImage:@"",
                                     @"score"   :self.workGradeTextField.text
                                     };
            
            [NetManager Post:LLBaseURL(@"assignHomework.do") Auth:YES Params:Params Success:^(id Obj) {
                if ([Obj[@"code"] integerValue] == 1000) {
                    [SVProgressHUD showSuccessWithStatus:@"批阅成功"];
                    if (self.successBlock) {
                        self.successBlock();
                    }
                    [self.navigationController popViewControllerAnimated:YES];
                }else {
                    [SVProgressHUD showErrorWithStatus:Obj[@"msg"]];
                }
                
            } Fail:^(NSError *Error) {
                [SVProgressHUD showErrorWithStatus:NetErr];
            }];
           
//            [NetManager Post:LLBaseURL(@"assignHomework.do") Auth:YES Params:Params Success:^(id Obj) {
//                if ([Obj[@"code"] integerValue] == 1000) {
//                    [SVProgressHUD showSuccessWithStatus:@"批阅成功"];
//                }else {
//                    [SVProgressHUD showErrorWithStatus:Obj[@"msg"]];
//                }
//
//            } Fail:^(NSError *Error) {
//                [SVProgressHUD showErrorWithStatus:NetErr];
//            }];
            
        } else {
            [SVProgressHUD showErrorWithStatus:@"请输入正确的分数"];
        }
        
    } else {
        [SVProgressHUD showErrorWithStatus:@"请输入评分"];
    }
    
    
    
}



#pragma mark - 选择作业评语相机按钮(音频视频语音)

- (IBAction)clickCommenButton:(id)sender {
    
     __weak __typeof(&*self)weakSelf = self;
    
    if (self.isDelect) {
         [self AlertControllerOfTitle:@"是否删除该文件?" StringArr:@[@"确定"] CallBack:^(NSInteger Index, NSString *Str) {
             [self.workRemarkButton setImage:[UIImage imageNamed:@"bg_add_picture"] forState:(UIControlStateNormal)];
             weakSelf.files = nil;
             weakSelf.vedioStr = nil;
             weakSelf.isDelect = NO;
             weakSelf.vedioImage = nil;
             self.SaveVideo = NO;
         }];
        
        
    } else {
        
        NSArray *Arr = nil;
        if (self.SaveVideo == YES) {
            
            Arr = @[@"图片上传", @"音频上传"];
            
        }else{
            
              Arr = @[@"图片上传", @"音频上传",@"视频上传"];
        }
        
        [self AlertControllerOfTitle:@"请选择操作项" StringArr:Arr CallBack:^(NSInteger Index, NSString *Str) {
            
            // 图片
            if ([Str isEqualToString:@"图片上传"] && Index == 0) {
                
                [self ClickImage:sender];
            }
            
            // 音频
            if ([Str isEqualToString:@"音频上传"] && Index == 1) {
                
                [self ClickAudio:sender];
            }
            
            // 视频
            if ([Str isEqualToString:@"视频上传"] && Index == 2) {
                
                [self ClickVideo:sender];
            }
        }];
        
    }
    
    
}

- (UIImagePickerController *)ImagePicker
{
    if (!_ImagePicker)
    {
        _ImagePicker = [[UIImagePickerController alloc] init];
        _ImagePicker.delegate = self;
        _ImagePicker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        _ImagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        _ImagePicker.navigationBar.tintColor = [UIColor whiteColor];
        _ImagePicker.navigationBar.barTintColor = [UIColor colorWithRed:20.f/255.0 green:24.0/255.0 blue:38.0/255.0 alpha:1];
    }
    return _ImagePicker;
}


//#pragma mark - Func
///** 将需要展示的内容放进数组里，回调事件的顺序Index及相对应的Str */
- (void)AlertControllerOfTitle:(NSString *)Title StringArr:(NSArray <NSString *>*)StringArr CallBack:(void (^)(NSInteger Index, NSString *Str))CallBack {

    UIAlertController *Alert = [UIAlertController alertControllerWithTitle:Title message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
    [StringArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [Alert addAction:[UIAlertAction actionWithTitle:obj style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            CallBack ? CallBack(idx, obj) : nil;
        }]];
    }];
    [Alert addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil]];
    [self presentViewController:Alert animated:YES completion:nil];
}

#pragma mark - 点击了图片上传
- (void)ClickImage:(UIButton *)Button {
    
    [self AlertControllerOfTitle:@"请选择图片选择方式" StringArr:@[@"拍摄", @"从相册中选择"] CallBack:^(NSInteger Index, NSString *Str) {
        if (Index == 0) {
            
            self.ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:self.ImagePicker animated:YES completion:nil];
        }
        
        if (Index == 1) {
            
            self.ImagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
            [self presentViewController:self.ImagePicker animated:YES completion:nil];
        }
    }];
}

#pragma mark - 相册代理
//适用获取所有媒体资源，只需判断资源类型
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    
//    //如果是视频资源
    NSURL *sourceURL = info[UIImagePickerControllerMediaURL];
//
     __weak __typeof(&*self)weakSelf = self;
    if (sourceURL != nil) {
        [picker dismissViewControllerAnimated:YES completion:^{

            NSString *Str = [sourceURL absoluteString];
            Str = [Str substringFromIndex:8];
            NSInteger   fileSize = [[NSFileManager defaultManager] attributesOfItemAtPath:Str error:nil].fileSize / 1024 / 1024;
            if (fileSize <= 0)
            {
                MyHappyTimeVC *VC = [[MyHappyTimeVC alloc] init];
                VC.urlBlock = ^(NSString *urlStr, NSString *urlImg) {
                    
                    NSLog(@"%@",urlImg);
                    
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                         [weakSelf.workRemarkButton zy_setImageWithUrl:urlImg];
                    });
                    
                   
//                    [weakSelf.workRemarkButton sd_setImageWithURL:[NSURL URLWithString:urlImg] forState:(UIControlStateNormal)];
                    weakSelf.vedioStr = urlStr;
                    weakSelf.isDelect = YES;
                    weakSelf.isVedio = YES;
                    weakSelf.vedioImage = urlImg;
                    self.SaveVideo = YES;
//                    [self VideoUploadSuccessUrlStr:urlStr urlImg:urlImg ImgPath:Str];
                };

                VC.VideoPath = Str;
                [self.navigationController pushViewController:VC animated:YES];
            }
            else
            {
                NSString *Message = [NSString stringWithFormat:@"您选择的视频文件大小为%ld(兆)，上传需要花费较长时间，是否继续上传？",fileSize];
                // 跳转至视频上传
                UIAlertController *Alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:Message preferredStyle:(UIAlertControllerStyleAlert)];
                [Alert addAction:[UIAlertAction actionWithTitle:@"继续" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
                    MyHappyTimeVC *VC = [[MyHappyTimeVC alloc] init];

                    VC.urlBlock = ^(NSString *urlStr, NSString *urlImg) {
//                        [weakSelf.workRemarkButton sd_setImageWithURL:[NSURL URLWithString:urlImg] forState:(UIControlStateNormal)];
                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                             [weakSelf.workRemarkButton zy_setImageWithUrl:urlImg];
                        });
                       
                        weakSelf.vedioStr = urlStr;
                        weakSelf.isDelect = YES;
                        weakSelf.isVedio = YES;
                        weakSelf.vedioImage = urlImg;
                        self.SaveVideo = YES;
//                        [self VideoUploadSuccessUrlStr:urlStr urlImg:urlImg ImgPath:Str];
                    };


                    VC.VideoPath = Str;
                    [self.navigationController pushViewController:VC animated:YES];
                }]];
                [Alert addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil]];
                [self presentViewController:Alert animated:YES completion:nil];
            }
        }];
    } else {
    
        // 图片
        [picker dismissViewControllerAnimated:YES completion:^{
            // 如果是图片
            UIImage *Img = info[UIImagePickerControllerOriginalImage];
            [self UploadImg:Img Complete:^(NSString *ImgName) {
                [self.workRemarkButton setImage:Img forState:(UIControlStateNormal)];
                self.files = ImgName;
                self.isDelect = YES;
                self.isVedio = NO;
                
            }];
            
        }];
    }
}

#pragma mark - 网络
// 上传图片
- (void)UploadImg:(UIImage *)Img Complete:(void(^)(NSString *ImgName))Complete
{
    [MBProgressHUD showHUD];
    [NetManager UpdataImgWithURL:LLBaseURLTeacher(@"upload.do") Img:Img parameter:@{@"action":@"uploadimage"} success:^(id obj) {
        
        __block NSString *Str = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            Str = [Str stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
            Str = [Str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
            // 上传成功，设置图片
            Complete (Str);
        });
        
    } fail:^(NSError *error) {
        [MBProgressHUD showError:@"图片上传失败"];
    }];
}


#pragma mark - 点击了音频上传
- (void)ClickAudio:(UIButton *)Button {
    
    // 得到音频的数据了
    [self UploadAVAudioComplete:^(NSString *ImgName) {
        
        ImgName = [ImgName stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
        ImgName = [ImgName stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        
//        // 新建按钮的
//        UIButton *Button = [self CreatImgBtn:[UIImage imageNamed:@"btn_mp3"]];
//        // 加入数组
//        [self.ImgArr addObject:@{ImgName:Button}];
        [self.workRemarkButton setImage:[UIImage imageNamed:@"iocn_voice"] forState:(UIControlStateNormal)];
        self.files = ImgName;
        self.isDelect = YES;
        self.isVedio = NO;
    }];
}

// 上传音频
- (void)UploadAVAudioComplete:(void(^)(NSString *ImgName))Complete
{
    [[UIApplication sharedApplication].keyWindow addSubview:[CourseEvaluateAudioView ConsumeSureWithClickCommit:^(BOOL IsSelect) {
        
        // 录音切换
        IsSelect ? [self MgrBeginAudio]:[self MgrCloseAudioComplete:Complete];
    }]];
}

/**
 开始录音
 */
- (void)MgrBeginAudio
{
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"download/aaa"];
    
    [[EMCDDeviceManager sharedInstance] asyncStartRecordingWithFileName:path completion:^(NSError *error)
     {
     }];
    
}

/**
 停止录间并上传
 */
- (void)MgrCloseAudioComplete:(void(^)(NSString *ImgName))Complete
{
    [[EMCDDeviceManager sharedInstance] asyncStopRecordingWithCompletion:^(NSString *recordPath, NSInteger aDuration, NSError *error) {
        
        if (recordPath.length != 0) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [MBProgressHUD showHUD];
                [NetManager UpdataAudioWithURL:LLBaseURLTeacher(@"upload.do") FilePath:recordPath parameter:@{@"action":@"uploadimage"} success:^(id obj) {
                    
                    NSString *Str = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        // 上传成功，设置图片
                        Complete (Str);
                    });
                    
                } fail:^(NSError *error) {
                    [MBProgressHUD showError:@"音频上传失败"];
                }];
            });
        }
        
        // 主线程更新图片
    }];
}

#pragma mark - 点击了视频上传
- (void)ClickVideo:(UIButton *)Button {
    
    
    [self AlertControllerOfTitle:@"请选择视频选择方式" StringArr:@[@"拍摄", @"从相册中选择"] CallBack:^(NSInteger Index, NSString *Str) {
        if (Index == 0) {
            
            [self Action_GoCamera:Button];
        }
        
        if (Index == 1) {
            
            [self Action_Select:Button];
        }
    }];
}

- (BOOL)isSimulator {
#if TARGET_OS_SIMULATOR
    return YES;
#else
    return NO;
#endif
}

/** 进入拍摄 */
- (void)Action_GoCamera:(UIButton *)Button{
    if (![self isSimulator]) {
        MBSmartVideoView *smart = [[MBSmartVideoView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [self.navigationController.view addSubview:smart];
        __weak __typeof(&*self)weakSelf = self;
        [smart setFinishedRecordBlock:^(NSDictionary *info) {
            
            MyHappyTimeVC *vc = [MyHappyTimeVC new];
            
            vc.urlBlock = ^(NSString *urlStr, NSString *urlImg) {
 
                //上传成功拿到图片和地址了
//                [weakSelf.workRemarkButton sd_setImageWithURL:[NSURL URLWithString:urlImg] forState:(UIControlStateNormal)];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                     [weakSelf.workRemarkButton zy_setImageWithUrl:urlImg];
                });
              
                
             
                
              
                weakSelf.vedioStr = urlStr;
                weakSelf.isDelect = YES;
                weakSelf.isVedio = YES;
                weakSelf.vedioImage = urlImg;
                weakSelf.SaveVideo = YES;
            };
            
            self.SaveVideo = YES;
            vc.VideoPath = [[info objectForKey:@"videoURL"] description];
            [self.navigationController pushViewController:vc animated:YES];
            
        }];
    } else {
        NSLog(@"模拟器不支持小视频录制");
    }
}

/** 从相册中选择 */
- (void)Action_Select:(UIButton *)Button {
    
    UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
    pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    pickerImage.delegate = self;
    // 设定显示数据的类型，全部为视频
    pickerImage.mediaTypes = @[(NSString*)kUTTypeMovie,(NSString*)kUTTypeVideo,(NSString*)kUTTypeAudiovisualContent,(NSString*)kUTTypeAudio,(NSString*)kUTTypeQuickTimeMovie,(NSString*)kUTTypeMPEG,(NSString*)kUTTypeMPEG2Video,(NSString*)kUTTypeMPEG2TransportStream,(NSString*)kUTTypeMPEG4,(NSString*)kUTTypeMPEG4Audio,(NSString*)kUTTypeAppleProtectedMPEG4Audio,(NSString*)kUTTypeAppleProtectedMPEG4Video,(NSString*)kUTTypeAVIMovie,(NSString*)kUTTypeAudioInterchangeFileFormat,(NSString*)kUTTypeWaveformAudio,(NSString*)kUTTypeMIDIAudio];
    
    
    [pickerImage.navigationBar setBarTintColor:ColorRGB(58, 203, 140)];
    [pickerImage.navigationBar setTranslucent:NO];
    [pickerImage.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    [self presentViewController:pickerImage animated:YES completion:nil];
}



@end
